﻿
using System ;

using MskEdit.Dxf.Representation ;
using MskEdit.Dxf.Model ;


namespace MskEdit.Dxf.Backend
{
    internal static class DxfCodeReader
    {
        internal static DxfCode TryPeek( string[] allLines, int lineNo, DxfCode fallbackCode ) {
                        
            string codeStr = DxfLineReader.TryPeek( allLines, lineNo, null ) ;
            
            if ( codeStr == null )
                return fallbackCode ;
                                
            DxfCode dxfCode = DxfCode.TryFrom( allLines[lineNo], null ) ;
            
            if ( dxfCode == null )
                return fallbackCode ;
                        
            return dxfCode ;
        }


        public static DxfCode TryRead( string[] allLines, ref int lineNo, DxfCode fallbackCode ) {
                                                        
            DxfCode dxfCode = TryPeek( allLines, lineNo, null ) ;
            
            if ( dxfCode == null )
                return fallbackCode ;
            
            lineNo += 1 ;
            
            return dxfCode ;
        }
    }
}
